package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ByHistoryFile;
import com.ruoyi.system.service.IByHistoryFileService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * HistoryFileController
 * 
 * @author ruoyi
 * @date 2024-07-29
 */
@RestController
@RequestMapping("/system/HistoryFile")
public class ByHistoryFileController extends BaseController
{
    @Autowired
    private IByHistoryFileService byHistoryFileService;

    /**
     * 查询HistoryFile列表
     */
    @PreAuthorize("@ss.hasPermi('system:HistoryFile:list')")
    @GetMapping("/list")
    public TableDataInfo list(ByHistoryFile byHistoryFile)
    {
        startPage();
        List<ByHistoryFile> list = byHistoryFileService.selectByHistoryFileList(byHistoryFile);
        return getDataTable(list);
    }

    /**
     * 查询HistoryFile列表
     */
    @GetMapping("/scanFile")
    public AjaxResult scanFile()
    {
        byHistoryFileService.scanFile();
        return AjaxResult.success("开始扫描，请等待结束，请勿重复点击按钮");
    }

    /**
     * 导出HistoryFile列表
     */
    @PreAuthorize("@ss.hasPermi('system:HistoryFile:export')")
    @Log(title = "HistoryFile", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ByHistoryFile byHistoryFile)
    {
        List<ByHistoryFile> list = byHistoryFileService.selectByHistoryFileList(byHistoryFile);
        ExcelUtil<ByHistoryFile> util = new ExcelUtil<ByHistoryFile>(ByHistoryFile.class);
        util.exportExcel(response, list, "HistoryFile数据");
    }

    /**
     * 获取HistoryFile详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:HistoryFile:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(byHistoryFileService.selectByHistoryFileById(id));
    }

    /**
     * 新增HistoryFile
     */
    @PreAuthorize("@ss.hasPermi('system:HistoryFile:add')")
    @Log(title = "HistoryFile", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ByHistoryFile byHistoryFile)
    {
        return toAjax(byHistoryFileService.insertByHistoryFile(byHistoryFile));
    }

    /**
     * 修改HistoryFile
     */
    @PreAuthorize("@ss.hasPermi('system:HistoryFile:edit')")
    @Log(title = "HistoryFile", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ByHistoryFile byHistoryFile)
    {
        return toAjax(byHistoryFileService.updateByHistoryFile(byHistoryFile));
    }

    /**
     * 删除HistoryFile
     */
    @PreAuthorize("@ss.hasPermi('system:HistoryFile:remove')")
    @Log(title = "HistoryFile", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(byHistoryFileService.deleteByHistoryFileByIds(ids));
    }
}
